package com.woniu.supermarket.web;

import com.woniu.supermarket.result.ResultResponse;
import com.woniu.supermarket.service.IPurchaseDetailService;
import com.woniu.supermarket.service.impl.PurchaseDetailServiceImpl;
import com.woniu.supermarket.vo.PurchaseDetailVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("PurchaseDetail")
@Api(value = "采购订单详情操作")
public class PurchaseDetailController {


    @Autowired
    PurchaseDetailServiceImpl iPurchaseDetailService;

    @GetMapping("/showPurchaseDetail/{id}")
    @ApiOperation(value = "通过采购订单id查询订单详情信息")
    public ResultResponse<List<PurchaseDetailVo>> showPurchaseDetail(@PathVariable("id")Integer id){
        System.out.println(id+"===id");
        ResultResponse<List<PurchaseDetailVo>> result = null;
        try {
            List<PurchaseDetailVo> lists = iPurchaseDetailService.findAllPurchaseDetailByPurchaseId(id);
            result = new ResultResponse<>(200,"查询采购订单详情成功",lists);
        }catch (RuntimeException e){
            e.printStackTrace();
            result = new ResultResponse<>(201,"查询采购订单详情失败");
        }
        return result;
    }


    @GetMapping("/showPurchaseDetailOfPurchase/{purchaseNumber}")
    @ApiOperation(value = "审核订单，修改订单审核状态")
    public ResultResponse<List<PurchaseDetailVo>> showPurchaseDetailOfPurchase(@PathVariable String purchaseNumber) {
        ResultResponse<List<PurchaseDetailVo>> result = null;
        try {
            List<PurchaseDetailVo> lists = iPurchaseDetailService.findAllPurchaseDetailByPurchaseNumber(purchaseNumber);
            if(lists!=null){
                result = new ResultResponse<>(200,"查询采购订单详情成功",lists);
            }else{
                result = new ResultResponse<>(201,"查询采购订单详情失败");
            }
        } catch (RuntimeException e) {
            e.printStackTrace();
            result = new ResultResponse<>(555,"系统错误");
        }
        return result;
    }

}
